package com.weixing.mall.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.weixing.mall.provider.mapper.GoodsImgMapper;
import com.weixing.mall.provider.model.domain.GoodsImg;
import com.weixing.mall.provider.service.IGoodsImgService;
import org.apache.commons.collections.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.applet.Main;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author wx
 * @Date 2019/8/12 17:29
 * @Version 1.0
 */
/**
 * <p>
 * 商品模块-商品图片表 服务实现类
 * </p>
 *
 * @author Small
 * @since 2019-11-20
 */
@Service
public class GoodsImgServiceImpl extends ServiceImpl<GoodsImgMapper, GoodsImg> implements IGoodsImgService {

    @Autowired
    private GoodsImgMapper goodsImgMapper;

    @Override
    public void save(Long goodsId, List<String> goodsImg) {
        //首先根据商品Id将图片进行删除
       goodsImgMapper.deleteByGoods(goodsId);
       //在进行添加
        for (String img : goodsImg) {
            GoodsImg goodsimg = new GoodsImg();
            goodsimg.setGoodsId(goodsId);
            goodsimg.setGoodsImg(img);
            save(goodsimg);
        }
    }

    @Override
    public List<String> selectGoodsImg(Long goodsId) {
        /*LambdaQueryWrapper<GoodsImg> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GoodsImg::getGoodsId,goodsId);
        List<GoodsImg> list = list(queryWrapper);
        return list.stream().map(GoodsImg::getGoodsImg).collect(Collectors.toList());*/
        return  baseMapper.findGoodsImgByGoodsId(goodsId);
    }
}
